﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using cms.libs;

namespace CMS
{
    public partial class ReportAccount : System.Web.UI.Page
    {
        private int AccountID = 0;
        private int RoomID = 0;
        private DataTable lst2 = null;
        private DataTable lst3 = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                txtFromDate.SelectedDate = DateTime.Now.AddDays(-10);
                txtToDate.SelectedDate = DateTime.Now;
                BindData();
            }
        }
        protected void BindData()
        {
            DateTime fromD = txtFromDate.SelectedDate.Value;
            DateTime toD = txtToDate.SelectedDate.Value;
            string AccountName = txtAccName.Text.Trim();
            DataTable lst = new DBAccountReport().GetListDataTable(AccountName, fromD, toD);

            GridView1.DataSource = lst;
            GridView1.DataBind();
        }

        protected void BindData2()
        {
            lst2 = new DBAccountReport().GetListByAccountId(txtFromDate.SelectedDate.Value,
                    txtToDate.SelectedDate.Value, int.Parse(hfAccountID.Value));

            GridView2.DataSource = lst2;
            GridView2.DataBind();
        }
        protected void BindData3()
        {
            lst3 = new DBAccountReport().GetListByACcIdAndRoomId(int.Parse(hfDateReport.Value), int.Parse(hfAccountID.Value), int.Parse(hfRoomID.Value));

            GridView3.DataSource = lst3;
            GridView3.DataBind();
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            GridView2.DataSource = null;
            GridView2.DataBind();
            GridView3.DataSource = null;
            GridView3.DataBind();
            BindData();
        }
        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            BindData();
        }
        protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView2.PageIndex = e.NewPageIndex;
            BindData2();
        }
        protected void GridView3_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView3.PageIndex = e.NewPageIndex;
            BindData3();
        }
        protected void grdCustomPagging_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "VIEW")
            {
                GridView2.DataSource = null;
                GridView2.DataBind();
                GridView3.DataSource = null;
                GridView3.DataBind();

                hfAccountID.Value = e.CommandArgument.ToString();

                BindData2();
            }
        }

        protected void grdCustomPagging1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "VIEW")
            {
                GridView3.DataSource = null;
                GridView3.DataBind();
                string detail = e.CommandArgument.ToString();
                hfAccountID.Value = detail.Split(new Char[] { '|' })[0];
                hfRoomID.Value = detail.Split(new Char[] { '|' })[1];
                hfDateReport.Value = detail.Split(new Char[] { '|' })[2];

                BindData3();
            }
        }

    }
}